cmake_minimum_required(VERSION 3.0)

project(ros1_protobuf_msg_bridge)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  rosbag
  std_msgs
  actionlib
  actionlib_msgs
  message_generation
)


# BEGIN 以下为使用protobuf所需的配置
find_package(Protobuf REQUIRED)
list(APPEND catkin_LIBRARIES ${Protobuf_LIBRARYS})
list(APPEND catkin_INCLUDE_DIRS ${Protobuf_INCLUDE_DIR})

# 引入处理proto的cmake基础配置
set(PROTO_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/proto)
include(${CMAKE_CURRENT_SOURCE_DIR}/../proto_ros_gen/ProtobufROSGen.cmake)
message(CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR})


file(GLOB_RECURSE PROTO_MSGS ${CMAKE_CURRENT_SOURCE_DIR}/proto/${PROJECT_NAME}/msg/*.proto)
message(PROTO_MSGS=${PROTO_MSGS})
generate_proto_cpp_msg(PROTO_SRCS PROTO_HDRS  ${PROTO_MSGS}) # 生成proto的cpp源文件
list(APPEND HDRS ${PROTO_HDRS})
list(APPEND SRCS ${PROTO_SRCS})
generate_proto_python_msg(PROTO_PY    ${PROTO_MSGS}) # 生成proto的python源文件
message(PROTO_PY=${PROTO_PY})
generate_proto_ros_msg(${PROTO_PY}) # 生成proto对接ros的msg源文件(cpp+python)


file(GLOB_RECURSE PROTO_SRVS ${CMAKE_CURRENT_SOURCE_DIR}/proto/${PROJECT_NAME}/srv/*.proto)
generate_proto_cpp_srv(PROTO_SRV_SRCS PROTO_SRV_HDRS ${PROTO_SRVS})
list(APPEND HDRS ${PROTO_SRV_HDRS})
list(APPEND SRCS ${PROTO_SRV_SRCS})
generate_proto_python_srv(PROTO_PY ${PROTO_SRVS})
generate_proto_ros_srv(${PROTO_PY})


file(GLOB_RECURSE PROTO_ACTS ${CMAKE_CURRENT_SOURCE_DIR}/proto/${PROJECT_NAME}/action/*.proto)
generate_proto_cpp_action(PROTO_ACT_SRCS PROTO_ACT_HDRS ${PROTO_ACTS})
list(APPEND HDRS ${PROTO_ACT_HDRS})
list(APPEND SRCS ${PROTO_ACT_SRCS})
generate_proto_python_action(PROTO_PY ${PROTO_ACTS})
generate_proto_ros_action(${PROTO_PY})


# 将proto对接ros的msg编译成静态库
add_library(${PROJECT_NAME} STATIC  ${SRCS})
target_include_directories(${PROJECT_NAME} PUBLIC ${PROTOBUF_INCLUDE_DIRS} ${ROS_CPP_H_DEVEL_DIR} ${ROS_CPP_H_DEVEL_DIR}/${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})

# END 以上为使用protobuf所需的配置
